function   [shatnew,signew,lh,yhat,spred]=kfc(y,H,shat,sig,G,M,C)
% function [shatnew,signew,lh,yhat,spred]=kfc(y,H,shat,sig,G,M,C)
%
% Same as KF.m but with a constant in the transition equation 
% s(t)=C+Gs(t-1)+Me, 
% where e is N(0,I).  
% The observation equation is y(t)=Hs(t) 
% 
% Note: If there is a constant or exogenous components in the measurement
% equation this must have been removed before this code 
% SPRED = s(t)|t-1 = C + G*s(t-1)|t-1 
omega=G*sig*G'+M*M';
[uo do vo]=svd(omega);
[u d v]=svd(H*uo*sqrt(do));
first0=min(find(diag(d)<1e-12));
if isempty(first0),first0=min(size(H))+1;end
u=u(:,1:first0-1);
v=v(:,1:first0-1);
d=diag(d);d=diag(d(1:first0-1));
fac=vo*sqrt(do);
% s(t)|t-1=C+H*s(t-1)|t-1
spred=C+G*shat; 
% y(t)=H*s(t)|t-1
yhat=y-H*spred;
ferr=(v/d)*u'*yhat;
lh=-.5*ferr'*ferr-sum(log(diag(d)));
shatnew=fac*ferr+spred;
signew=fac*(eye(size(v,1))-v*v')*fac';
